﻿<%@ Page Title="" Language="C#" MasterPageFile="~/pages/Site.Master" AutoEventWireup="true" CodeBehind="SowManagement.aspx.cs" Inherits="WebAppTemplate.SowManagement" %>

<%@ Register Assembly="WYJ.Web.Controls" Namespace="WYJ.Web.Controls" TagPrefix="cc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <link href="../resources/css/jquery.ui.all.css" rel="stylesheet" type="text/css" />
     <script src="../resources/scripts/jquery-1.10.2.js" type="text/javascript"></script>
    <script src="../resources/scripts/jquery.ui.core.js" type="text/javascript"></script>
    <script src="../resources/scripts/jquery.ui.datepicker.js" type="text/javascript"></script>
    <script src="../resources/scripts/jquery.ui.widget.js" type="text/javascript"></script>
    <script src="../resources/scripts/jquery.ui.datepicker-zh-TW.js" type="text/javascript"></script>
    <script src="../resources/scripts/myAjax.js" type="text/javascript"></script>
    <script src="../resources/scripts/facebox.js" type="text/javascript"></script>
    <script src="../resources/scripts/sow.js" type="text/javascript"></script>
    <script src="../resources/scripts/jquery.cookie.js" type="text/javascript"></script>
    <script type="text/javascript" language="javascript">
        $(document).ready(function () {
            $("#txtDateIncome").datepicker($.datepicker.regional["zh-TW"]).datepicker("option", "dateFormat", "yy-mm-dd");
            $("#<%=txtBitID.ClientID %>").blur(function () {
                var bitId = $(this).val();
                if (bitId == '') {
                    // <span class="input-notification success png_bg">Successful message</span>
                    $("#spanBitMsg").text("母猪耳号不能为空，请重新填写。");
                    $("#btnSave").hide();

                } else {
                    $("#spanBitMsg").text("*");
                    $("#btnSave").show();
                }
            });
            $("#btnSave").click(function () {
                // var hoggerId = getCurrentHoggerID();
                var hoggerId = $.cookie("hoggeryId");
                var bitID = $("#<%=txtBitID.ClientID %>").val();
                var sowType = $("#<%=ddlSowType.ClientID %>").val();
                var sowScource = $("#<%=ddlSowScource.ClientID %>").val();
                var dateInFarm = $("#txtDateIncome").val();
                var pigPen = $("#<%=ddlPigPen.ClientID %>").val();
                var propagateState = $("#<%=ddlPropagateState.ClientID %>").val();
                var hybridizationCount = $("#txthybridizationCount").val();
                var propagateCount = $("#txtPropagateCount").val();
                var comment = $("#txtComment").val();

                $.ajax2({
                    type: "post",
                    contentType: "application/json",
                    url: "../WebServices/Sows.asmx/AddSow",
                    dataType: "json",
                    data: "{ hoggeryIDStr: '" + hoggerId + "',bitIDStr:'" + bitID + "',TypeIDStr:'" + sowType + "',SourceIDStr:'" + sowScource
                    + "',DateInFarmStr:'" + dateInFarm + "',PigPenIDStr:'" + pigPen + "',hybridizationCountStr:'" + hybridizationCount
                    + "',propagateCountStr:'" + propagateCount + "',propagateStateIDStr:'" + propagateState + "',comment:'" + comment + "' }",
                    success: function (data) {
                        if (data.d.Flag) {
                            $("#msg > div").remove();
                            var span = "<div class='notification success png_bg'> <a href='#' class='close'><img src='../resources/images/icons/cross_grey_small.png' title='关闭' alt='关闭' /></a><div>" + data.d.Message + "</div></div>";
                            $("#msg").append(span);
                            $("#<%=txtBitID.ClientID %>").val("");
                        } else {
                            $("#msg > div").remove();
                            var span = "<div class='notification attention png_bg'> <a href='#' class='close'><img src='../resources/images/icons/cross_grey_small.png' title='关闭' alt='关闭' /></a><div>" + data.d.Message + "</div></div>";
                            $("#msg").append(span);
                        }
                    },
                    error: function (error) {
                        $("#msg > div").remove();
                        var span = "<div class='notification error png_bg'> <a href='#' class='close'><img src='../resources/images/icons/cross_grey_small.png' title='关闭' alt='关闭' /></a><div>提交失败：" + error.status + "</div></div>";
                        $("#msg").append(span);
                    }

                });


            });

            $("#linkTab2").click(function () {
                var hoggerId = getCurrentHoggerID();
                var href = $("#linkPigPen").attr("href") + "?id=" + hoggerId;
                $("#linkPigPen").attr("href", href);
            });

            $("a[name=linkUpdate]").click(function () {
                var hoggerId = getCurrentHoggerID();
                var href = $(this).attr("href") + "&&hoggeryId=" + hoggerId;
                alert(href);
                $(this).attr("href", href);
            });

        });

        function deleteSow(sid, bitId, pigType, dateJoinfarm, customizeID) {
            var hogger = getCurrentHoggerID();
            var url = "SowDelete.aspx?sowId=" + sid + "&bitId=" + bitId + "&hogger=" + hogger + "&type=" + pigType + "&date=" + dateJoinfarm + "&pigPen=" + customizeID;
            location.href = url;
        }

    </script>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
      <!-- Start Content Box -->
      <div class="content-box-header">
        <h3>母猪管理</h3>
        <ul class="content-box-tabs">
          <li><a href="#tab1" class="default-tab">查看母猪资料</a></li>
          <!-- href must be unique and match the id of target div -->
          <li><a id="linkTab2" href="#tab2">添加母猪资料</a></li>
        </ul>
        <div class="clear"></div>
      </div>   
      <!-- End .content-box-header -->
      <div class="content-box-content">
        <div class="tab-content default-tab" id="tab1">
          <!-- This is the target div. id must match the href of this div's tab -->
          <!--<div class="notification information png_bg"> <a href="#" class="close"><img src="../resources/images/icons/cross_grey_small.png" title="Close this notification" alt="close" /></a>
            <div><span> 2014年4月18日四川生猪价格行情，单位：元/斤。</span> </div>
          </div>-->
         <table>
            <thead>
              <tr>
                <th>
                  <input class="check-all" type="checkbox" />
                </th>
                <th>母猪耳号</th>
                <th>品种</th>
                <th>进场日期</th>
                <th>所在猪舍</th>
                <th>繁殖状态</th>
                <th>操作</th>
              </tr>
            </thead>
            <tfoot>
              <tr>
                <td colspan="6">
                    <div class="pagination">
                        <asp:DataPager ID="DataPager1" PagedControlID="rpSow" runat="server">
                            <Fields>
                                <asp:NextPreviousPagerField ShowFirstPageButton="True" ShowNextPageButton="False"
                                    ShowPreviousPageButton="False" FirstPageText="第一页" NextPageText="" />
                                <asp:NextPreviousPagerField ShowNextPageButton="False" 
                                    PreviousPageText="&amp;laquo; 前一页"  />
                                <asp:NumericPagerField CurrentPageLabelCssClass="number current" />
                                <asp:NextPreviousPagerField ShowPreviousPageButton="False" 
                                    NextPageText="下一页 &amp;raquo;" />
                                <asp:NextPreviousPagerField ShowNextPageButton="False"
                                    ShowPreviousPageButton="False" LastPageText="最后一页" 
                                    ShowLastPageButton="True" />
                            </Fields>
                        </asp:DataPager>
                    </div>
                <!-- End .pagination -->
                  <div class="clear"></div>
                </td>
              </tr>
            </tfoot>
            <tbody>
                <cc1:DataPagerRepeater ID="rpSow" runat="server" PersistentDataSource="true">
                  <ItemTemplate>
                    <tr>
                        <td> <input type="checkbox" /></td>
                        <td>
                            <a href="SowDetail.aspx?id=<%#Eval("SowID") %>" title="查看母猪详细信息" rel="modal"><%#Eval("BitID") %></a>
                        </td>
                        <td><%#Eval("pigType") %></td>
                        <td><%#Eval("DateJoinFarm", "{0:yyyy年MM月dd日}")%></td>
                        <td><%#Eval("CustomizeID")%></td>
                        <td><%#Eval("PropagateStateName")%></td>
                        <td style="display:none"><%#Eval("HybridizationCount")%></td>
                        <td style="display:none"><%#Eval("PropagateCount")%></td>
                        <td style="display:none"><%#Eval("Comment")%></td>
                         <td>
                            <!-- Icons -->
                            <a href="SowUpdate.aspx?id=<%#Eval("SowID") %>&&bitId=<%#Eval("BitID") %>&&pigPenId=<%#Eval("CustomizeID")%> &&hybridizationCount=<%#Eval("HybridizationCount")%>&&propagateCount=<%#Eval("PropagateCount")%>&&comment=<%#Eval("Comment")%>" title="修改" rel="modal">
                                <img src="../resources/images/icons/pencil.png" alt="修改" />
                             </a> 
                            <a onclick="deleteSow('<%#Eval("SowID")%>','<%#Eval("BitID") %>','<%#Eval("pigType") %>','<%#Eval("DateJoinFarm", "{0:yyyy年MM月dd日}")%>','<%#Eval("CustomizeID")%>');" title="删除">
                               <img src="../resources/images/icons/cross.png" alt="删除" />
                            </a> 
                        </td>
                    </tr>
                </ItemTemplate>
                </cc1:DataPagerRepeater>
            </tbody>
          </table>
         
        </div>

         
        
        <div class="tab-content" id="tab2">
          
          <asp:UpdatePanel ID="UpdatePanel1" runat="server">
          <ContentTemplate>
         <div class="notification attention png_bg"> <a href="#" class="close"><img src="../resources/images/icons/cross_grey_small.png" title="Close this notification" alt="close" /></a>
            <div> 红色星号 <span style=" color:Red">*</span>为必填项目 </div>
          </div>
         
        
            <fieldset>
            <!-- Set class to "column-left" or "column-right" on fieldsets to divide the form into columns -->
             <p>
              <label>母猪耳号</label>
                 <asp:TextBox ID="txtBitID" runat="server" CssClass="text-input medium-input datepicker"></asp:TextBox>
                <span id="spanBitMsg" style="color:Red">*耳号一旦录入不能修改。</span>
      <!--        <input class="text-input small-input" type="text" id="small-input" name="small-input" />-->
             <%-- <span class="input-notification success png_bg">Successful message</span>--%>
              <!-- Classes for input-notification: success, error, information, attention -->
              <br />
            </p>
              
            <p>
              <label>母猪品种</label>
                <asp:DropDownList ID="ddlSowType" runat="server" AutoPostBack="false">
                </asp:DropDownList>
            </p>
            <p>
              <label>母猪来源</label>
                <asp:DropDownList ID="ddlSowScource" runat="server" AutoPostBack="false">
                </asp:DropDownList>
            </p>
            <p>
              <label>进场日期</label>
             <input class="text-input small-input" type="text" id="txtDateIncome" name="small-input" />
            </p>
            <p>
                <label>可用猪圈编号</label>
                <asp:DropDownList runat="server" ID="ddlPigPen" AutoPostBack="false"></asp:DropDownList>
                <a href="javascript:void(0)">查看所有猪圈</a>
                 <a href="AddPigPen.aspx" rel="modal" id="linkPigPen">添加猪圈</a>
            </p>
            <p>
              <label>配种次数</label>
               <input class="text-input small-input" type="text" id="txthybridizationCount" name="small-input" value="0" />
             <small>请输入数字,不填即为0</small>
             </p>
            <p>
              <label>已生产胎数</label>
                <input class="text-input small-input" type="text" id="txtPropagateCount" name="small-input" value="0" />
              <small>请输入数字，不填即为0</small>
             </p>
            <p>
              <label>繁育状态</label>
              <asp:DropDownList ID="ddlPropagateState" runat="server" CssClass="small-input" AutoPostBack="false"></asp:DropDownList>
           
            </p>
            <p>
              <label>备注说明</label>
                <textarea id="txtComment" cols="20" rows="4"></textarea>
            </p>
            <p>
              <input class="button" id="btnSave" value="保存" />
             </p>
             <p></p>
             <p>
                <div id="msg"></div>
             </p>
            </fieldset>
            <div class="clear"></div>
            <!-- End .clear -->
             </ContentTemplate>
          </asp:UpdatePanel>
        </div>
         
      </div>
      <!-- End .content-box-content -->
      <!--popup-->
    <!--end popup-->
</asp:Content>
